import {Injectable} from '@angular/core';
import {RouterService} from '@kylin/router';
import {UserService} from '@kylin/core';
import {CacheService} from '@kylin/cache';
import {environment} from '../../environments/environment';
import {HttpService} from '@kylin/http';

@Injectable()
export class HomeService {

    constructor(private routerService: RouterService,
                private userService: UserService,
                private http: HttpService,
                private cacheService: CacheService
    ) {
    }

    /**
     * 登出
     */
    logout() {
        this.routerService.navigate('/login');
        this.cacheService.remove('siderData');
        this.cacheService.remove('token');
        this.userService.clearUser();
    }

    /**
     * 用于在进入home页面时候验证用户是否已经登陆,如果没有登陆,那么跳转到登陆页面
     */
    getSidebarMenuData() {
        if (false) {
            return this.cacheService.get('siderData').menuList;
        } else {
            return [
                {
                    name: '系统监控',
                    url: '',
                    icon: 'video-camera',
                    childMenu: [
                        {
                            name: '数据库监控',
                            url: '/home/system-monitoring/database',
                            childMenu: []
                        },
                        {
                            name: '消息监控',
                            url: '/home/system-monitoring/news',
                            childMenu: []
                        },
                        {
                            name: '服务监控',
                            url: '/home/system-monitoring/service',
                            childMenu: []
                        }
                    ]
                },
                {
                    name: 'API',
                    url: '',
                    icon: 'api',
                    childMenu: [
                        {
                            name: 'swagger',
                            url: '/home/api/swagger',
                            childMenu: []
                        }
                    ]
                },
                {
                    name: '认证管理',
                    url: '',
                    icon: 'setting',
                    childMenu: [
                        {
                            name: '用户管理',
                            url: '/home/identity-managment/user-managment',
                            childMenu: []
                        },
                        {
                            name: '角色管理',
                            url: '/home/identity-managment/role-managment',
                            childMenu: []
                        }
                    ]
                },
                {
                    name: 'hex',
                    url: '',
                    icon: 'setting',
                    childMenu: [
                        {
                            name: '用户1',
                            url: '/home/file/list',
                            childMenu: []
                        }
                    ]
                }
            ];
        }
    }
}
